package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IInvoiceContractService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.InvoiceContractCreateValidate;
import com.mdd.admin.validate.InvoiceContractUpdateValidate;
import com.mdd.admin.validate.InvoiceContractSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.InvoiceContractListedVo;
import com.mdd.admin.vo.InvoiceContractDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/invoice")
@Api(tags = "新建合同发票列管理")
public class InvoiceContractController {

    @Resource
    IInvoiceContractService iInvoiceContractService;

    @GetMapping("/list")
    @ApiOperation(value="新建合同发票列列表")
    public AjaxResult<PageResult<InvoiceContractListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated InvoiceContractSearchValidate searchValidate) {
        PageResult<InvoiceContractListedVo> list = iInvoiceContractService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="新建合同发票列详情")
    public AjaxResult<InvoiceContractDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        InvoiceContractDetailVo detail = iInvoiceContractService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "新建合同发票列新增")
    @PostMapping("/add")
    @ApiOperation(value="新建合同发票列新增")
    public AjaxResult<Object> add(@Validated @RequestBody InvoiceContractCreateValidate createValidate) {
        iInvoiceContractService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "新建合同发票列编辑")
    @PostMapping("/edit")
    @ApiOperation(value="新建合同发票列编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody InvoiceContractUpdateValidate updateValidate) {
        iInvoiceContractService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "新建合同发票列删除")
    @PostMapping("/del")
    @ApiOperation(value="新建合同发票列删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iInvoiceContractService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
